package com.gexiaobao.pigeon.ui.adapter

import android.annotation.SuppressLint
import android.graphics.Paint
import androidx.appcompat.widget.AppCompatTextView
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.base.DataBindBaseViewHolder
import com.gexiaobao.pigeon.app.model.bean.AppTeamListResponse
import com.gexiaobao.pigeon.databinding.ItemAppTeamListBinding

/**
 * @Author      : hxw
 * @Date        : 2024/6/26 16:20
 * @Describe    :
 */
class AppTeamListAdapter(data: ArrayList<AppTeamListResponse.ListBean>) :
    BaseQuickAdapter<AppTeamListResponse.ListBean, DataBindBaseViewHolder>(R.layout.item_app_team_list, data) {

    @SuppressLint("ResourceAsColor")
    override fun convert(holder: DataBindBaseViewHolder, item: AppTeamListResponse.ListBean) {
        val binding = DataBindBaseViewHolder.getBinding(holder) as ItemAppTeamListBinding
        binding.data = item
        binding.executePendingBindings()//防止列表抖动

        val tvSignPeopleSearch = holder.getView<AppCompatTextView>(R.id.tvSignPeopleSearch)
        val tvGroupProcedure = holder.getView<AppCompatTextView>(R.id.tvGroupProcedure)
        tvSignPeopleSearch.paint.flags = Paint.UNDERLINE_TEXT_FLAG
        tvGroupProcedure.paint.flags = Paint.UNDERLINE_TEXT_FLAG

        var state = ""
        var backgroundId = 0
        var colorId = 0
        when (item.status) {//状态 1-未开始 2-进行中 3-已结束
            1 -> {
                state = context.getString(R.string.item_train_fly_main_list_not_start)//"未开始"
                backgroundId = R.drawable.round_btn_gray10_bg
                colorId = ContextCompat.getColor(context,R.color.comm_text_gray_light)
            }

            2 -> {
                state = context.getString(R.string.underway)//"进行中"
                backgroundId = R.drawable.round_btn_5a5a5a_5radiu_bg
                colorId = ContextCompat.getColor(context,R.color.white)
            }

            else -> {
                state = context.getString(R.string.finished)//"已结束"
                backgroundId = R.drawable.round_btn_gray10_bg
                colorId = ContextCompat.getColor(context,R.color.comm_text_gray_light)
            }
        }

        holder.setText(R.id.tvGroupState, state)
        holder.setBackgroundResource(R.id.tvGroupState, backgroundId)
        holder.setTextColor(R.id.tvGroupState, colorId)
    }
}